/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.scs.model.tableModel;

import com.wisnu.scs.entity.DbBarangKeluar;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Wisnu Wardoyo
 */
public class DbBarangKeluarTableModel extends AbstractTableModel {

    private List<DbBarangKeluar> list = new ArrayList<>();

    public void setList(List<DbBarangKeluar> list) {
        this.list = list;
    }
    
    public boolean add(DbBarangKeluar element) {
        try {
            return list.add(element);
        } finally {
            fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
        }
    }

    public DbBarangKeluar get(int i) {
        return list.get(i);
    }

    public DbBarangKeluar set(int index, DbBarangKeluar element) {
        try {
            return list.set(index, element);
        } finally {
            fireTableRowsUpdated(index, index);
        }
    }

    public DbBarangKeluar remove(int index) {
        try {
            return list.remove(index);
        } finally {
            fireTableRowsDeleted(index, index);
        }
    }
    

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return 7;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return list.get(rowIndex).getIdKeluar();
            case 1:
                return list.get(rowIndex).getDbBarang().getNamaBarang();
            case 2:
                return list.get(rowIndex).getTanggalKeluar();
            case 3:
                return list.get(rowIndex).getPemohon();
            case 4:
                return list.get(rowIndex).getKeperluan();
            case 5:
                return list.get(rowIndex).getJumlah();
            case 6:
                return list.get(rowIndex).getKeterangan();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int index) {
        switch (index) {
            case 0:
                return "ID Keluar";
            case 1:
                return "Nama Barang";
            case 2:
                return "Tanggal Keluar";
            case 3:
                return "Pemohon";
            case 4:
                return "Keperluan";
            case 5:
                return "Jumlah";
            case 6:
                return "Keterangan";
            default:
                return null;
        }
    }

}
